import OrderModel from '../../models/order/order'
class Order{
    constructor(){}
    async getOrderList(req,res,next){
        const {limit=10,offset=0}=req.query
        console.log(limit+'~~'+offset)
        try {
            const order=await OrderModel.find({},'-_id').sort({user_id:1}).limit(Number(limit)).skip(Number(offset))
            res.send({
                status:1,
                order:order
            })
        } catch (error) {
            res.send({
                status:0,
                type:'ERROR_GET_DATE',
                message:'获取数据失败'
            })
        }
    }
    async getOrderCount(req,res,next){
        const restaurant_id=req.query.restaurant_id
        try {
            let filter={}
            if (restaurant_id && Number(restaurant_id)) {
                filter={restaurant_id}
            }
            const count =await OrderModel.find(filter).count()
            res.send({
                status:1,
                count
            })
        } catch (error) {
            res.send({
                status:0,
                type:'ERROR_TO_GET_COUNT',
                message:'获取订单数量失败'
            })
        }
    }
}
export default new Order()